package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.util.TDevice;

/**
 * Created by Administrator on 2016/6/28.
 */
   public class ShareItemImageAdapter extends BaseAdapter{

    private Context context;
    private List<String> shareList;

    public ShareItemImageAdapter(Context context, List<String> shareList){
        this.context=context;
        this.shareList=shareList;
    }

    @Override
    public int getCount() {
        return shareList != null ? shareList.size():0;
    }

    @Override
    public Object getItem(int i) {
        return shareList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public void clear(){
        shareList.clear();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder=null;
        if(view == null){
            viewHolder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.sharelist_item_img,null);
            viewHolder.share_img_item= (ImageView) view.findViewById(R.id.share_img);

            int width = (int)(TDevice.getScreenWidth()-90)/3;
            LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(width,width);
            viewHolder.share_img_item.setLayoutParams(params2);

            view.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }
        final String des=shareList.get(i);
        System.out.println("HuaG="+OKUtilAPI.imgBaseUrl+des);
        Glide.with(context).load(OKUtilAPI.imgBaseUrl+des).into(viewHolder.share_img_item);

        return view;
    }

    public class ViewHolder{
        ImageView share_img_item;
    }
}
